<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
.uploadify-button {
	width: 30px;
}

.uploadify-queue-item {
	background: #fff;
}

.upload-btn {
	background-color: red;
}
</style>
<script type="text/javascript">
    var taskfinishDataGrid;
    $(function() {
    	taskfinishDataGrid = $('#taskfinishDataGrid').datagrid({
            url : '${path}/process/myfinishedProcess',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'startTime',
            sortOrder : 'desc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
            	{
                    field: 'processInstanceId',
                    title: '流程ID',
                    width:100
                }, {
                    field: 'taskId',
                    title: '任务ID',
                    width:100
                },
                {
                    field: 'taskName',
                    title: '任务名称',
                    width:100
                },
                {
                    field: 'title',
                    title: '标题',
                    width:200
                },{
                    field: 'businessType',
                    title: '类型',
                    width:200
                }, {
                    field: 'user_name',
                    title: '申请人',
                    width:100
                }, {
                    field: 'startTime',
                    title: '开始时间',
                    width:100,
                    formatter: function(value, row, index) {
                    	if(value==null){
                     	   	 return "";
                     	 	}
                        var date=new Date(value);
      	               	 var y = date.getFullYear();
      	               	 var m = date.getMonth() + 1;  
      	               	 if(m < 10) m = "0" + m;
      	               	 var d = date.getDate();  
      	               	 if(d < 10) d = "0" + d;
      	               	 var h = date.getHours();
      	               	 if(h < 10) h = "0" + h;
      	               	 var min = date.getMinutes();
      	               	 if(min < 10) min = "0" + min;
      	               	 var s=date.getSeconds();
      	               	 if(s<10)s="0"+s;
                      return y+"/"+m+"/"+d+" "+h+":"+min+":"+s;
                   }
                },{
                    field: 'endTime',
                    title: '结束时间',
                    width:100,
                    formatter: function(value, row, index) {
                    	if(value==null){
                     	   	 return "";
                     	 	}
                        var date=new Date(value);
      	               	 var y = date.getFullYear();
      	               	 var m = date.getMonth() + 1;  
      	               	 if(m < 10) m = "0" + m;
      	               	 var d = date.getDate();  
      	               	 if(d < 10) d = "0" + d;
      	               	 var h = date.getHours();
      	               	 if(h < 10) h = "0" + h;
      	               	 var min = date.getMinutes();
      	               	 if(min < 10) min = "0" + min;
      	               	 var s=date.getSeconds();
      	               	 if(s<10)s="0"+s;
                      return y+"/"+m+"/"+d+" "+h+":"+min+":"+s;
                   }
                },  {
                        field: 'version',
                        title: '版本号'
                },
                {
                    field : 'action',
                    title : '操作',
                    width : 200,
                    formatter : function(value, row, index) {
                         var str = '';
                        	  str += $.formatString('<a href="javascript:;" class="taskfinish-easyui-linkbutton-revoke" data-options="plain:true,iconCls:\'fi-refresh icon-blue\'" onclick="doRevokeTask(\'{0}\',\'{1}\')">撤销</a>',row.taskId,row.processInstanceId);
                        	  str+="&nbsp;&nbsp;|&nbsp;&nbsp;";
                        	  str += $.formatString('<a href="javascript:;" class="taskfinish-easyui-linkbutton-view" data-options="plain:true,iconCls:\'fi-magnifying-glass\'" onclick="viewFinishTaskEnityInfo(\'{0}\',\'{1}\')">查看</a>',row.businessKey,row.processInstanceId);
                		return str;
                    }
                }
            ]],
            onLoadSuccess:function(data){
                $('.taskfinish-easyui-linkbutton-revoke').linkbutton({text:'撤销'});
                $('.taskfinish-easyui-linkbutton-view').linkbutton({text:'查看'});
            },
            toolbar : '#taskfinishToolbar'
        });
    });
   
	function viewFinishTaskEnityInfo(businessKey,processInstanceId){
		 var title="查看";
		 var url="${ctxPath}/example/"+businessKey+"/view"+businessKey+"info/"+processInstanceId;
		  var dialog= $('<div>').dialog({
		        title:title,
		        href:url,
		        width : '80%',
		        height : '80%',
		        modal:true,
		        onClose : function() {
		            $(this).dialog('destroy');
		        },
		        buttons:[{
		            text:'关闭',
		            handler:function () {
		            	dialog.dialog('close');
		            }
		        }]
		  })
	}

    function doRevokeTask(taskId,processInstanceId){
			 parent.$.messager.confirm('询问', '确认要撤销任务ID为'+taskId+'的任务吗？', function(b) {
		            if (b) {
		                progressLoad();
		                $.post('${path }/task/revoke/'+taskId+'/'+processInstanceId, {
		                   
		                }, function(result) {
		                    if (result.success) {
		                         showMsg(result.msg)
		                        taskfinishDataGrid.datagrid('reload');
		                    } else {
		                        parent.$.messager.alert('错误', result.msg, 'error');
		                    }
		                    progressClose();
		                }, 'JSON');
		            }
		        });
    }
    function searchprocessInstanceFinishFun() {
    	taskfinishDataGrid.datagrid('load', $.serializeObject($('#searchprocessInstanceFinishForm')));
    }
    function cleanprocessInstanceFinishFun() {
        $('#searchprocessInstanceFinishForm')[0].reset();
        taskfinishDataGrid.datagrid('load', {});
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
<div data-options="region:'north',border:true,title:''" style="overflow: hidden;background-color: #fff;">
        <form id="searchprocessInstanceFinishForm" >
            <table>
                <tr>
              <td>标题</td>
			  <td>
				<input name="title"   type="text" placeholder="请输入标题" class="easyui-text  span2" >
			 </td>

              <td>流程实例ID</td>
			  <td>
				<input name="processInstanceId"   type="text" placeholder="请输入流程实例ID" class="easyui-text  span2" >
			 </td>
			 <td>流程发起时间</td>
			  <td>
			<input name="startTimeStart"  type="text"  class="easyui-text easyui-datebox  span2"  >
			~<input name="startTimeEnd"  type="text"  class="easyui-text easyui-datebox  span2"  >
			</td>
			 </tr>
			 <tr>
			 <td>发起人</td>
			 <td>
			 	<input type="hidden" name="userid" id="taskfinish_userid"/>
			 	<input type="text" name="userName" class="easyui-text" id="taskfinish_userid_disp" 
			 	 onfocus="selectUser(false,'taskfinish_userid','taskfinish_userid_disp')"/>
			 </td>
			 <td>流程类型</td>
			 <td>
			 	<%-- <select name="businessKey" class="easyui-text" style="height:28px;width:140px">
			 		<option value="">请选择</option>
			 		<c:forEach var="processType" items="${processTypes}">
			 			<option value="${processType.key }">${processType.name }</option>
			 		</c:forEach> 
			 	</select> --%>
			 	<input type="hidden" name="businessKey" id="taskfinish_businessKey"/>
			 	<input type="text" name="businessType" class="easyui-text" id="taskfinish_businessKey_disp" 
			 	 onfocus="selectProcessType(false,'taskfinish_businessKey','taskfinish_businessKey_disp')"/>
			 	
			 </td>
			<td>
			  <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchprocessInstanceFinishFun();">查询</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanprocessInstanceFinishFun();">清空</a>
			</td></tr>

            </table>
        </form>
    </div>
    <div data-options="region:'center',border:true">
        <table id="taskfinishDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="taskfinishToolbar" style="display: none;">
</div>
